from djitellopy import Tello
import cv2
import pyzbar.pyzbar as pyzbar

tello = Tello()
tello.connect()

#tello.takeoff()
tello.streamon()

while True:
    img = tello.get_frame_read().frame
    frame = pyzbar.decode(img)
    # 显示解码结果
    for obj in frame:
        print('二维码数据:', obj.data.decode('utf-8'))

    # 显示视频流
    rgb_frame = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    cv2.imshow('Video Stream', rgb_frame)

    # 如果用户按下 'q' 键，则退出循环
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

#tello.land()
cv2.destroyAllWindows()